package de.fuberlin.inf.alp3.ue01;

import de.fuberlin.inf.alp3.utils.ConsoleInput;

public class StringQueueTest {
    public static void main(String[] args) {
        Queue<String> q = new StringQueue();

        System.out.println("A new StringQueue object has been created.");
        int userInput = -1;
        while (true) {
            System.out.println("  1. Append a String to the end of the " +
                "StringQueue");
            System.out.println("  2. Insert a String at the beginning of the " +
                "StringQueue");
            System.out.println("  3. Remove a String");
            System.out.println("  4. Count Items of the StringQueue.");
            System.out.println("\n  0. Exit application");
            userInput = ConsoleInput.readInt("Your choice?", "Not a number!");
            switch (userInput) {
            case 0:
                System.out.println("Bye...");
                System.exit(0);
            case 1:
                // Cast it or catch an exception, that is never thrown
                ((StringQueue) q).
                    append(ConsoleInput.readString("Enter String"));
                break;
            case 2:
                // Cast it, because insert() is not specified in the interface
                ((StringQueue) q).
                    insert(ConsoleInput.readString("Enter String"));
                break;
            case 3:
                try {
                    System.out.println(q.remove() + " removed.");
                } catch (QueueUnderflow e) {
                    System.out.println("Error: " + e.getMessage());
                }
                break;
            case 4:
                System.out.println("Size: " + q.length());
                break;
            default:
                System.out.println("Please choose from available options.");
            }
        }
    }
}